//
//  TestViewController.m
//  ProfilePicture
//
//  Created by 张云江 on 2019/10/14.
//  Copyright © 2019年 张云江. All rights reserved.
//

#import "TestViewController.h"
#import "HomeCollectionViewCell.h"

static NSString *cellId = @"TestView_Identifier";

@interface TestViewController () <UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView  *ordinaryCollectionView;
@property (nonatomic, strong) NSMutableArray    *headArray;

@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)creatUI
{
    self.customNavBar.hidden = YES;
    self.headArray = [NSMutableArray array];
    
    HomeInfoMode *info = [[HomeInfoMode alloc] init];
    [info setSizeW:285 withSizeH:385 withName:@"导游证" withSizeDes:@"285 x 385 px" withSpecId:299];
    [self.headArray addObject:info];
    HomeInfoMode *info1 = [[HomeInfoMode alloc] init];
    [info1 setSizeW:295 withSizeH:413 withName:@"教师资格证" withSizeDes:@"295 x 413 px" withSpecId:31];
    [self.headArray addObject:info1];
    HomeInfoMode *info2 = [[HomeInfoMode alloc] init];
    [info2 setSizeW:295 withSizeH:413 withName:@"入学照" withSizeDes:@"295 x 413  px" withSpecId:539];
    [self.headArray addObject:info2];
    HomeInfoMode *info3 = [[HomeInfoMode alloc] init];
    [info3 setSizeW:413 withSizeH:531 withName:@"国考" withSizeDes:@"413 x 531 px" withSpecId:22];
    [self.headArray addObject:info3];
    HomeInfoMode *info4 = [[HomeInfoMode alloc] init];
    [info4 setSizeW:413 withSizeH:626 withName:@"国家司法考试" withSizeDes:@"413 x 626 px" withSpecId:34];
    [self.headArray addObject:info4];
    HomeInfoMode *info5 = [[HomeInfoMode alloc] init];
    [info5 setSizeW:295 withSizeH:413 withName:@"二级建造师证" withSizeDes:@"295 x 413 px" withSpecId:194];
    [self.headArray addObject:info5];
    HomeInfoMode *info6 = [[HomeInfoMode alloc] init];
    [info6 setSizeW:472 withSizeH:630 withName:@"一级建造师证" withSizeDes:@"472 x 630 px" withSpecId:358];
    [self.headArray addObject:info6];
    HomeInfoMode *info7 = [[HomeInfoMode alloc] init];
    [info7 setSizeW:455 withSizeH:661 withName:@"二级建造师证" withSizeDes:@"455 x 661 px" withSpecId:367];
    [self.headArray addObject:info7];
    HomeInfoMode *info8 = [[HomeInfoMode alloc] init];
    [info8 setSizeW:230 withSizeH:334 withName:@"职业兽医资格证" withSizeDes:@"230 x 334 px" withSpecId:257];
    [self.headArray addObject:info8];
    HomeInfoMode *info9 = [[HomeInfoMode alloc] init];
    [info9 setSizeW:384 withSizeH:512 withName:@"成人自考" withSizeDes:@"384 x 512 px" withSpecId:365];
    [self.headArray addObject:info9];
    HomeInfoMode *info10 = [[HomeInfoMode alloc] init];
    [info10 setSizeW:294 withSizeH:413 withName:@"成人自考" withSizeDes:@"294 x 413 px" withSpecId:196];
    [self.headArray addObject:info10];
    HomeInfoMode *info11 = [[HomeInfoMode alloc] init];
    [info11 setSizeW:413 withSizeH:531 withName:@"公务员考试" withSizeDes:@"413 x 531 px" withSpecId:470];
    [self.headArray addObject:info11];
    HomeInfoMode *info12 = [[HomeInfoMode alloc] init];
    [info12 setSizeW:295 withSizeH:413 withName:@"会计从业资格证" withSizeDes:@"295 x 413 px" withSpecId:210];
    [self.headArray addObject:info12];
    HomeInfoMode *info13 = [[HomeInfoMode alloc] init];
    [info13 setSizeW:144 withSizeH:172 withName:@"英语四六级考试" withSizeDes:@"144 x 172 px" withSpecId:250];
    [self.headArray addObject:info13];
    HomeInfoMode *info14 = [[HomeInfoMode alloc] init];
    [info14 setSizeW:144 withSizeH:192 withName:@"英语四六级考试" withSizeDes:@"144 x 192 px" withSpecId:256];
    [self.headArray addObject:info14];
    HomeInfoMode *info15 = [[HomeInfoMode alloc] init];
    [info15 setSizeW:240 withSizeH:320 withName:@"英语四六级考试" withSizeDes:@"240 x 320 px" withSpecId:261];
    [self.headArray addObject:info15];
    HomeInfoMode *info16 = [[HomeInfoMode alloc] init];
    [info16 setSizeW:390 withSizeH:567 withName:@"英语AB级考试" withSizeDes:@"390 x 567 px" withSpecId:399];
    [self.headArray addObject:info16];
    HomeInfoMode *info17 = [[HomeInfoMode alloc] init];
    [info17 setSizeW:390 withSizeH:567 withName:@"普通话水平测试" withSizeDes:@"390 x 567 px" withSpecId:401];
    [self.headArray addObject:info17];
    HomeInfoMode *info18 = [[HomeInfoMode alloc] init];
    [info18 setSizeW:390 withSizeH:567 withName:@"全国计算机考试" withSizeDes:@"390 x 567 px" withSpecId:29];
    [self.headArray addObject:info18];
    HomeInfoMode *info19 = [[HomeInfoMode alloc] init];
    [info19 setSizeW:295 withSizeH:413 withName:@"执业药师资格考试" withSizeDes:@"295 x 413 px" withSpecId:420];
    [self.headArray addObject:info19];
    HomeInfoMode *info20 = [[HomeInfoMode alloc] init];
    [info20 setSizeW:413 withSizeH:579 withName:@"执业药师资格考试" withSizeDes:@"413 x 579 px" withSpecId:421];
    [self.headArray addObject:info20];
    
    HomeInfoMode *info21 = [[HomeInfoMode alloc] init];
    [info21 setSizeW:354 withSizeH:472 withName:@"执业医师资格报名" withSizeDes:@"354 x 472 px" withSpecId:355];
    [self.headArray addObject:info21];
    HomeInfoMode *info22 = [[HomeInfoMode alloc] init];
    [info22 setSizeW:358 withSizeH:441 withName:@"学籍照片" withSizeDes:@"358 x 441 px" withSpecId:368];
    [self.headArray addObject:info22];
    HomeInfoMode *info23 = [[HomeInfoMode alloc] init];
    [info23 setSizeW:295 withSizeH:413 withName:@"入学报名" withSizeDes:@"295 x 413  px" withSpecId:413];
    [self.headArray addObject:info23];
    HomeInfoMode *info24 = [[HomeInfoMode alloc] init];
    [info24 setSizeW:413 withSizeH:531 withName:@"大学入学" withSizeDes:@"413 x 531 px" withSpecId:422];
    [self.headArray addObject:info24];
    HomeInfoMode *info25 = [[HomeInfoMode alloc] init];
    [info25 setSizeW:420 withSizeH:560 withName:@"高考报名" withSizeDes:@"420 x 560 px" withSpecId:30];
    [self.headArray addObject:info25];
    HomeInfoMode *info26 = [[HomeInfoMode alloc] init];
    [info26 setSizeW:571 withSizeH:800 withName:@"全国计算机考试" withSizeDes:@"571 x 800 px" withSpecId:27];
    [self.headArray addObject:info26];
    HomeInfoMode *info27 = [[HomeInfoMode alloc] init];
    [info27 setSizeW:472 withSizeH:630 withName:@"一级建造师证" withSizeDes:@"472 x 630 px" withSpecId:358];
    [self.headArray addObject:info27];
    HomeInfoMode *info28 = [[HomeInfoMode alloc] init];
    [info28 setSizeW:210 withSizeH:276 withName:@"护士执业资格考试" withSizeDes:@"210 x 276 px" withSpecId:474];
    [self.headArray addObject:info28];
    HomeInfoMode *info29 = [[HomeInfoMode alloc] init];
    [info29 setSizeW:340 withSizeH:450 withName:@"公务员考试报名" withSizeDes:@"340 x 450 px" withSpecId:470];
    [self.headArray addObject:info29];
    HomeInfoMode *info30 = [[HomeInfoMode alloc] init];
    [info30 setSizeW:480 withSizeH:720 withName:@"成人自考" withSizeDes:@"480 x 720 px" withSpecId:196];
    [self.headArray addObject:info30];
    HomeInfoMode *info31 = [[HomeInfoMode alloc] init];
    [info31 setSizeW:390 withSizeH:567 withName:@"自考学位外语考试" withSizeDes:@"390 x 390 px" withSpecId:196];
    [self.headArray addObject:info31];
    HomeInfoMode *info32 = [[HomeInfoMode alloc] init];
    [info32 setSizeW:480 withSizeH:640 withName:@"英语四级考试" withSizeDes:@"480 x 640 px" withSpecId:23];
    [self.headArray addObject:info32];
    HomeInfoMode *info33 = [[HomeInfoMode alloc] init];
    [info33 setSizeW:160 withSizeH:200 withName:@"二级建造师" withSizeDes:@"160 x 200 px" withSpecId:194];
    [self.headArray addObject:info33];
    HomeInfoMode *info34 = [[HomeInfoMode alloc] init];
    [info34 setSizeW:130 withSizeH:170 withName:@"二级建造师" withSizeDes:@"130 x 170 px" withSpecId:202];
    [self.headArray addObject:info34];
    HomeInfoMode *info35 = [[HomeInfoMode alloc] init];
    [info35 setSizeW:144 withSizeH:192 withName:@"英语AB级考试" withSizeDes:@"144 x 192 px" withSpecId:399];
    [self.headArray addObject:info35];
    HomeInfoMode *info36 = [[HomeInfoMode alloc] init];
    [info36 setSizeW:144 withSizeH:192 withName:@"英语三级考试" withSizeDes:@"144 x 192 px" withSpecId:290];
    [self.headArray addObject:info36];
    HomeInfoMode *info37 = [[HomeInfoMode alloc] init];
    [info37 setSizeW:130 withSizeH:170 withName:@"公务员考试" withSizeDes:@"130 x 170 px" withSpecId:470];
    [self.headArray addObject:info37];
    HomeInfoMode *info38 = [[HomeInfoMode alloc] init];
    [info38 setSizeW:455 withSizeH:661 withName:@"二级建造师" withSizeDes:@"455 x 661 px" withSpecId:493];
    [self.headArray addObject:info38];
    HomeInfoMode *info39 = [[HomeInfoMode alloc] init];
    [info39 setSizeW:295 withSizeH:413 withName:@"公务员考试" withSizeDes:@"295 x 413 px" withSpecId:470];
    [self.headArray addObject:info39];
    HomeInfoMode *info40 = [[HomeInfoMode alloc] init];
    [info40 setSizeW:210 withSizeH:270 withName:@"保险职业认证" withSizeDes:@"210 x 270 px" withSpecId:470];
    [self.headArray addObject:info40];
    HomeInfoMode *info41 = [[HomeInfoMode alloc] init];
    [info41 setSizeW:178 withSizeH:220 withName:@"注册会计师" withSizeDes:@"178 x 220 px" withSpecId:405];
    [self.headArray addObject:info41];
    HomeInfoMode *info42 = [[HomeInfoMode alloc] init];
    [info42 setSizeW:210 withSizeH:370 withName:@"保险职业证" withSizeDes:@"210 x 370 px" withSpecId:405];
    [self.headArray addObject:info42];
    
    self.view.backgroundColor = kUIColorFromRGB(0xF3F5FF);
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.minimumInteritemSpacing = kRatio(2);
    layout.minimumLineSpacing = kRatio(20);
    layout.footerReferenceSize = CGSizeMake(kScreenWidth, kRatio(40));
    CGFloat itemW = (kScreenWidth - kRatio(80))/2;
    CGFloat itemH = itemW;
    
    layout.itemSize = CGSizeMake(itemW, itemH);
    self.ordinaryCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(kRatio(30), 0, self.view.frame.size.width - kRatio(60), kScreenHeight - kRatio(260)) collectionViewLayout:layout];
    [self.ordinaryCollectionView registerClass:[UICollectionView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeadCollectionView"];
    [self.ordinaryCollectionView registerClass:[HomeCollectionViewCell class] forCellWithReuseIdentifier:cellId];
    self.ordinaryCollectionView.backgroundColor = [UIColor clearColor];
    self.ordinaryCollectionView.showsVerticalScrollIndicator = NO;
    self.ordinaryCollectionView.delegate = self;
    self.ordinaryCollectionView.dataSource = self;
    [self.view addSubview:self.ordinaryCollectionView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView
     numberOfItemsInSection:(NSInteger)section
{
    return self.headArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId
                                                                             forIndexPath:indexPath];
    HomeInfoMode *info = self.headArray[indexPath.row];
    [cell updateInfo:info];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomeInfoMode *info = self.headArray[indexPath.row];
    self.onCellClick(info);
}
@end
